const util = require('../../utils/util.js');
const api = require('../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:"",
    degree:"",
    school:"",
    major:"",
    share:"",
    contact:"",
    columnsType: [
      { name: '国内', id: 1 },
      { name: '国外', id: 2}
    ],
    columnsDegree: [
      { name: '本科', id: 1 },
      { name: '硕士', id: 2 },
      { name: '博士', id: 3 },
      { name: '硕博连读', id: 4 },
      { name: '博士后', id: 5 },
    ],
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var userId = wx.getStorageSync('userInfo').id //获取用户id
    if (userId == null || userId == undefined) {
      wx.navigateTo({
        url: "../authorize/authorize"
      })
    }
  },

  //提交
  submit(){
    let that = this;
    //校验
    if(this.data.type == ""){
      wx.showToast({
        title: '类型不能为空',
        icon: "none"
      })
    } else if (this.data.degree == ""){
      wx.showToast({
        title: '学位不能为空',
        icon: "none"
      })
    } else if (this.data.school == "") {
      wx.showToast({
        title: '学校不能为空',
        icon: "none"
      })
    } else if (this.data.major == "") {
      wx.showToast({
        title: '专业不能为空',
        icon:"none"
      })
    }else{
      util.request(api.Publish, {
        userId: wx.getStorageSync('userInfo').id,
        schoolType: Number(that.data.type) + 1,
        eductionType: Number(that.data.degree)+ 1,
        schoolName: that.data.school,
        specialName: that.data.major,
        selfShow: that.data.share,
        contact:that.data.contact
      }, 'POST',true).then(function (res) {
        if(res.code === 200){
          wx.navigateTo({
            url: `../teacherDetail/teacherDetail?from=index`
          })
        }else{
          wx.showToast({
            title: '修改失败',
            icon:"none"
          })
        }
      })
    }
  },

  //选择类型
  selectType(e){
    this.setData({
      type: e.detail.value
    })
  },

  //选择学位
  selectDegree(e){
    this.setData({
      degree: e.detail.value
    })
  },

  //输入学校
  bindSchoolInput(e){
    this.setData({
      school: e.detail.value
    });
  },

  //输入专业
  bindMajorInput(e) {
    this.setData({
      major: e.detail.value
    });
  },

  //分享
  bindLabelInput(e){
    this.setData({
      share: e.detail.value
    });
  },

  //输入联系方式
  bindContactInput(e) {
    this.setData({
      contact: e.detail.value
    });
  },
})